<template>
	<view class="content">
		<view class="list" v-if="token">
			<view class="list_item" v-for="item in message_list" @click="message_details(item.id)">
				<view :class="[item.status == 0?'p-r':'']" class="c1a f16 f-w">{{item.title}}</view>
				<view class="c76 f12 ov">{{item.desc}}</view>
				<view class="caa f14 mt-10">{{item.created_at}}</view>
			</view>
		</view>
		<view class="text_content f16 cc9" v-if="text">我也是有底线的~</view>
		<view class="t-c null" v-if="message_list.length <= 0">
			<image src="/static/null.png" mode="widthFix"></image>
			<text v-if="token">暂无内容</text>
		</view>
		<view v-if="!token" class="buts cff t-c f14" @click="log">
			立即登录
		</view>
	</view>
</template>

<script>
	import unis from '@/utils/util.js'
	export default {
		data() {
			return {
				page:1,
				page_size:10,
				message_list:[],
				lastPage:0,
				text:false,
				token:'',
				badge:0
			}
		},
		onLoad() {
		},
		onShow() {
			this.token = uni.getStorageSync('token')
			this.page = 1
			this.lists()
			this.unread()
		},
		methods: {
			unread(){
			unis.getData('/api/member/message/unread', 'get', {
			}, function (res) {
				if(res.code == 200){
					if(res.data.message_count > 0){
						var num = res.data.message_count.toString()
						uni.setTabBarBadge({
						  index: 1,
						  text: num
						})
					}
				}
			});
			},
			log(){
				uni.reLaunch({
					url: '/pages/index/index',
				})
				uni.clearStorageSync()
			},
			message_details(e){
				uni.navigateTo({
					url:'/pages/message_details/message_details?id='+e
				})
			},
			lists(){
				var that = this
				unis.getData('/api/member/message_log', 'get', {
					page:that.page,
					page_size:that.page_size,
				}, function (res) {
					if(res.code == 200){
						that.last_page = Math.ceil(res.data.total / that.page_size)
						if (that.page == 1) {
							that.message_list = res.data.list,
							that.text = false
						} else {
							that.message_list = that.message_list.concat(res.data.list),
							that.text = false
						}
					}else{
						that.token = ''
					}
				});
			},
		},
		onReachBottom(){
			if (this.page >= this.last_page) {
				this.text = true
			  return false
			}
			this.page++
			this.lists()
		},
	}
</script>

<style lang="scss" scoped>
.list{
	margin: 0px 16px;
	padding-top: 10px;
	.list_item{
		background-color: #fff;
		border-radius: 4px 4px 4px 4px;
		padding: 13px 24px;
		margin-bottom: 10px;
		.c76{
			margin-top: 3px;
		}
		.p-r{
			&:after{
				content:"";
				width: 6px;
				height: 6px;
				background: #FB5012;
				left: -10px;
				border-radius: 50%;
				top: 7px;
				position: absolute;
			}
		}
	}
}
.buts{
	width: 688rpx;
	height: 45px;
	background: linear-gradient( 270deg, #36A2FC 0%, #2D73FF 100%);
	border-radius: 4px 4px 4px 4px;
	line-height: 45px;
	position: fixed;
	bottom: 50%;
	left: 50%;
	transform: translate(-50%,-50%);
}
</style>
